package com.ict.web.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ict.common.core.domain.entity.SysDept;
import com.ict.common.core.domain.entity.SysRole;
import com.ict.common.core.domain.entity.SysUser;
import com.ict.common.utils.SecurityUtils;
import com.ict.common.utils.StringUtils;
import com.ict.common.utils.uuid.IdUtils;
import com.ict.system.mapper.SysUserMapper;
import com.ict.system.mapper.SysUserRoleMapper;
import com.ict.system.service.ISysDeptService;
import com.ict.system.service.ISysDictDataService;
import com.ict.system.service.ISysRoleService;
import com.ict.system.service.ISysUserService;
import com.ict.web.constant.Constants;
import com.ict.web.constant.ProjectStatusEnum;
import com.ict.web.controller.file.domain.YzqFile;
import com.ict.web.controller.file.service.IYzqFileService;
import com.ict.web.domain.*;
import com.ict.web.dto.*;
import com.ict.web.mapper.*;
import com.ict.web.msg.domain.SysMsg;
import com.ict.web.msg.util.CreateMsgUtil;
import com.ict.web.noteConfig.NoteConfig;
import com.ict.web.service.*;
import com.ict.web.vo.*;
import io.jsonwebtoken.lang.Collections;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

import static com.ict.common.utils.PageUtils.startPage;


/**
 * 评审任务Service业务层处理
 *
 * @author ruoyi
 * @date 2022-02-16
 */
@Service
public class ReviewTaskServiceImpl extends ServiceImpl<ReviewTaskMapper, ReviewTask> implements IReviewTaskService
{
    @Autowired
    private ReviewTaskMapper reviewTaskMapper;
    @Autowired
    private IExtractRuleService extractRuleService;
    @Autowired
    private IExtractReviewService extractReviewService;
    @Autowired
    private IExtractExpertService extractExpertService;
    @Autowired
    private IOrganizationManagementService organizationManagementService;
    @Autowired
    private IProjectManagementService projectManagementService;
    @Autowired
    private ExpertExtractMonitorMapper expertExtractMonitorMapper;
    @Autowired
    private IExpertCourseService expertCourseService;
    @Resource
    private IExpertInformationSheetService expertInformationSheetService;
    @Autowired
    private ISystemInfoService systemInfoService;
    @Autowired
    private IGovernmentDataResourcesService governmentDataResourcesService;
    @Autowired
    private ICloudResourceRequirementService cloudResourceRequirementService;
    @Autowired
    private IIotDeviceInfoService iotDeviceInfoService;
    @Autowired
    private ApprovalMapper approvalMapper;
    @Autowired
    private ISysDeptService deptService;
    @Autowired
    private IAnnualProjectPlanService annualProjectPlanService;
    @Resource
    private IApprovalService approvalService;
    @Resource
    private ISysDictDataService dictDataService;
    @Autowired
    private ExpertInformationSheetMapper expertInformationSheetMapper;
    @Autowired
    private IReviewTaskService reviewTaskService;
    @Resource
    private AnnualDeclarationMapper annualDeclarationMapper;
    @Resource
    private SchemeDeclarationMapper schemeDeclarationMapper;
    @Resource
    private IYzqFileService fileService;
    @Resource
    private ISysUserService userService;
    @Resource
    private ISysRoleService roleService;
    @Resource
    private SupplementaryDeclarationMapper supplementaryDeclarationMapper;
    @Resource
    private SysUserRoleMapper userRoleMapper;
    @Resource
    private ITechnicalTitleService technicalTitleService;
    @Resource
    private IExtractRuleService ruleService;
    @Resource
    private ExtractMonitoringService extractMonitoringService;
    @Resource
    private IExpertRuleDescService expertRuleDescService;
    @Autowired
    private ProjectSystemInfoService projectSystemInfoService;
    @Resource
    private SysUserMapper userMapper;
    /**
     * 专家详情查询（项目id）
     * @param proId 评审任务主键
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ReviewTask getReviewTaskInfo(Long proId) {
        ProjectManagement projectManagement = projectManagementService.getById(proId);
        Assert.isTrue(StringUtils.isNotNull(projectManagement),"未找到该评审任务的项目信息");
        ReviewTask reviewTask = reviewTaskMapper.selectById(projectManagement.getReviewTaskId());
        return reviewTask;
    }

    /**
     * 专家详情（专家id）
     * @param expertId
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public  ReviewTaskExpertThirdVo selectExpertById(Long reviewTaskId,Long expertId){
        ReviewTaskExpertThirdVo expertVo = new ReviewTaskExpertThirdVo();
        ReviewTask reviewTask = reviewTaskMapper.selectByExpertReviewTaskId(reviewTaskId,expertId);
        Assert.isTrue(StringUtils.isNotNull(reviewTask) && !reviewTask.getDelFlag().equals("1"),
                "专家评审任务不存在!!!");
        expertVo.setReviewTask(reviewTask);
        if(ReviewTask.REVIEW_TYPE_PROGRAMME.equals(reviewTask.getReviewType())){
            //项目管理信息
            QueryWrapper<ProjectManagement> projectQueryWrapper = new QueryWrapper<>();
            projectQueryWrapper.eq("review_task_id",reviewTaskId);
            projectQueryWrapper.eq("is_delete","0");
            ProjectManagement projectInfo = projectManagementService.getOne(projectQueryWrapper);
            //专家审核进度
            QueryWrapper<Approval> approvalQueryWrapper = new QueryWrapper<>();
            approvalQueryWrapper.eq("project_id",projectInfo.getProId());
            approvalQueryWrapper.eq("del_flag",Approval.DELETE_STATUS_NORMAL);
            approvalQueryWrapper.eq("approval_type",Approval.APPROVAL_TYPE_EXPERT);
            approvalQueryWrapper.eq("expert_id",expertId);
            approvalQueryWrapper.orderByAsc("start_time");
            List<Approval> thirdApprovalList = approvalMapper.selectList(approvalQueryWrapper);
            Assert.isTrue(thirdApprovalList.size() >= 0,"三方审核进度列表不存在!!!");
            List<ApprovalVo> approvalVoList = getApprovalVoList(thirdApprovalList);
            expertVo.setApprovalList(approvalVoList);
            expertVo.setApprovalStatus(approvalVoList.get(approvalVoList.size()-1).getApprovalStatus());
            expertVo.setProjectId(projectInfo.getProId());
            if ("0".equals(projectInfo.getNature())) {
                //年度项目
                AnnualDeclaration annulInfo = annualDeclarationMapper.selectById(projectInfo.getAnnualId());
                Assert.isTrue(StringUtils.isNotNull(annulInfo)&&  !annulInfo.getDelFlag().equals("1"),
                        "年度申报不存在!!!");
                //同步文件
                YzqFile filePP = fileService.getById(annulInfo.getProjectProposal());
                AnnualDeclarationVo annualDeclarationVo = new AnnualDeclarationVo();
                BeanUtils.copyProperties(annulInfo,annualDeclarationVo);
                annualDeclarationVo.setProjectProposalFile(filePP);
                expertVo.setAnnualDeclarationVo(annualDeclarationVo);
            }else if ("1".equals(projectInfo.getNature())){
                //增补项目
                SupplementaryDeclaration supplementaryInfo = supplementaryDeclarationMapper.selectById(projectInfo.getSupplementaryId());
                Assert.isTrue(StringUtils.isNotNull(supplementaryInfo)&&!supplementaryInfo.getDelFlag().equals("1"),
                        "增补申报不存在！！！");
                //同步文件
                YzqFile filePP = fileService.getById(supplementaryInfo.getProjectProposal());
                YzqFile fileSv = fileService.getById(supplementaryInfo.getSupplementaryVoucher());
                SupplementaryDeclarationVo supplementaryDeclarationVo = new SupplementaryDeclarationVo();

                BeanUtils.copyProperties(supplementaryInfo,supplementaryDeclarationVo);
                supplementaryDeclarationVo.setSupplementaryVoucherFile(fileSv);
                supplementaryDeclarationVo.setProjectProposalFile(filePP);
                expertVo.setSupplementaryDeclarationVo(supplementaryDeclarationVo);
            }

            //方案信息
            SchemeDeclaration schemeInfo = schemeDeclarationMapper.selectSchemeDeclarationByProgrammeId(projectInfo.getProgrammeId());
            if(StringUtils.isNotNull(schemeInfo)&& !schemeInfo.getDelFlag().equals("1")){
                SchemeDeclarationVo schemeDeclarationVo = new SchemeDeclarationVo();
                BeanUtils.copyProperties(schemeInfo,schemeDeclarationVo);
                if(StringUtils.isNotNull(schemeInfo)){
                    BeanUtils.copyProperties(schemeInfo,schemeDeclarationVo);
                    if(StringUtils.isNotNull(schemeInfo.getResearchReport())){
                        YzqFile fileRR = fileService.getById(schemeInfo.getResearchReport());
                        schemeDeclarationVo.setResearchReportFile(fileRR);
                    }
                    if(StringUtils.isNotNull(schemeInfo.getBudgetProposal())){
                        YzqFile fileBP = fileService.getById(schemeInfo.getBudgetProposal());
                        schemeDeclarationVo.setBudgetProposalFile(fileBP);
                    }
                    if(StringUtils.isNotNull(schemeInfo.getBudgetProgramme())){
                        YzqFile fileBPm = fileService.getById(schemeInfo.getBudgetProgramme());
                        schemeDeclarationVo.setBudgetProgrammeFile(fileBPm);
                    }
                    if(StringUtils.isNotNull(schemeInfo.getPreliminaryDesignScheme())){
                        YzqFile filePD = fileService.getById(schemeInfo.getPreliminaryDesignScheme());
                        schemeDeclarationVo.setPreliminaryDesignSchemeFile(filePD);
                    }
                    if(StringUtils.isNotNull(schemeInfo.getCloudResourceApplication())){
                        YzqFile fileCA = fileService.getById(schemeInfo.getCloudResourceApplication());
                        schemeDeclarationVo.setCloudResourceApplicationFile(fileCA);
                    }
                }
                expertVo.setSchemeDeclarations(schemeDeclarationVo);
                List<SystemInfoVo> systemInfoVos = systemInfoService.selectSystemInfoListByProgrammeIds(schemeInfo.getProgrammeId());
                List<SystemInfoVo> arrayList = new ArrayList<>();
                systemInfoVos.stream().forEach(s->{
                    SystemInfoVo systemInfoVo = new SystemInfoVo();
                    BeanUtils.copyProperties(s,systemInfoVo);
                    List<ProjectSystemInfo> list = projectSystemInfoService.lambdaQuery().eq(ProjectSystemInfo::getAppName, s.getSystemName()).list();
                    if(StringUtils.isNotEmpty(list)){
                        if(list.get(0).getAppIsCloud()){
                            systemInfoVo.setAppIsCloud("1");
                        }else {
                            systemInfoVo.setAppIsCloud("0");
                        }

                    }else {
                        systemInfoVo.setAppIsCloud("0");
                    }
                    arrayList.add(systemInfoVo);
                });
                expertVo.setSystemInfoVoList(arrayList);
                QueryWrapper<GovernmentDataResources> governmentQueryWrapper = new QueryWrapper<>();
                governmentQueryWrapper.eq("programme_id",schemeInfo.getProgrammeId());
                governmentQueryWrapper.eq("del_flag","0");
                List<GovernmentDataResources> governmentList = governmentDataResourcesService.list(governmentQueryWrapper);
                expertVo.setGovernmentDataResourcesVoList(governmentList);
                List<CloudResourceRequirementVo> cloudResourceRequirementVo =  cloudResourceRequirementService.selectCloudResourceListByProgrammeIds(schemeInfo.getProgrammeId());
                expertVo.setCloudResourceRequirementVoList(cloudResourceRequirementVo);
                List<IotDeviceInfoVo> iotDeviceInfoVo = iotDeviceInfoService.selectDeviceInfoListByProgrammeIds(schemeInfo.getProgrammeId());
                expertVo.setIotDeviceInfoVoList(iotDeviceInfoVo);
            }

        }else {
            AnnualProjectPlan annualProjectPlan = annualProjectPlanService.getById(reviewTask.getPlanId());
            Assert.isTrue(StringUtils.isNotNull(annualProjectPlan),"未找到该年度计划的评审信息");
            List<ProjectManagement> list = projectManagementService.lambdaQuery().eq(ProjectManagement::getPlanId, reviewTask.getPlanId())
                    .eq(ProjectManagement::getIsDelete, ExtractExpert.DELETE_STATUS_NORMAL).list();
            expertVo.setProjectManagementList(list);
            //专家审核进度
            QueryWrapper<Approval> approvalQueryWrapper = new QueryWrapper<>();
            approvalQueryWrapper.eq("plan_id",annualProjectPlan.getPlanId());
            approvalQueryWrapper.eq("del_flag",Approval.DELETE_STATUS_NORMAL);
            approvalQueryWrapper.eq("approval_type",Approval.APPROVAL_TYPE_EXPERT);
            approvalQueryWrapper.eq("expert_id",expertId);
            List<Approval> thirdApprovalList = approvalMapper.selectList(approvalQueryWrapper);

            List<ApprovalVo> approvalVoList = getApprovalVoList(thirdApprovalList);

            if(StringUtils.isNotEmpty(approvalVoList)){
                expertVo.setApprovalList(approvalVoList);
                expertVo.setApprovalStatus(approvalVoList.get(approvalVoList.size()-1).getApprovalStatus());
            }

        }

        return expertVo;
    }

    /**
     * 三方详情查询
     * @param reviewTaskId
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ReviewTaskExpertThirdVo selectThirdById(Long reviewTaskId) {
        ReviewTask reviewTaskThirdInfo = reviewTaskMapper.selectById(reviewTaskId);
        ReviewTaskExpertThirdVo thirdVo = new ReviewTaskExpertThirdVo();
        ReviewTaskThirdDetailVo reviewTaskThirdDetailVo =  reviewTaskMapper.selectThirdById(reviewTaskId);
        Assert.isTrue(StringUtils.isNotNull(reviewTaskThirdDetailVo) && reviewTaskThirdDetailVo.getOrmId() != null,"审核任务不存在");
        //判断机构是否存在
        QueryWrapper<OrganizationManagement> organizationQueryWrapper = new QueryWrapper<>();
        organizationQueryWrapper.eq("orm_id",reviewTaskThirdDetailVo.getOrmId());
        organizationQueryWrapper.eq("is_delete","0");
        Assert.isTrue(StringUtils.isNotNull(organizationManagementService.getOne(organizationQueryWrapper)),"机构不存在!!!");
        Assert.isTrue(reviewTaskThirdDetailVo.getIfExchangeThird().equals(ReviewTask.IF_EXCHANGE_THIRD_YES),"此评审任务不是三方的!!!");
        thirdVo.setReviewTask(reviewTaskThirdInfo);
        //获取项目id
        QueryWrapper<ProjectManagement> projectQueryWrapper = new QueryWrapper<>();
        projectQueryWrapper.eq("review_task_id", reviewTaskId);
        projectQueryWrapper.eq("is_delete","0");
        ProjectManagement projectInfo = projectManagementService.getOne(projectQueryWrapper);
        Assert.isTrue(StringUtils.isNotNull(projectInfo),"项目管理信息不存在!!!");
        //加入三方审核进度
        QueryWrapper<Approval> approvalQueryWrapper = new QueryWrapper<>();
        approvalQueryWrapper.eq("project_id",projectInfo.getProId());
        approvalQueryWrapper.eq("del_flag",Approval.DELETE_STATUS_NORMAL);
        approvalQueryWrapper.isNull("expert_id");
        List<Approval> thirdApprovalList = approvalMapper.selectList(approvalQueryWrapper);
        Assert.isTrue(thirdApprovalList.size() >= 0,"三方审核进度列表不存在!!!");
        List<Approval> collect = thirdApprovalList.stream().filter(s ->
                !s.getApprovalStatus().equals(ProjectStatusEnum.APPLICATION_REVIEW_PASSED.get().getStatus()) &&
                        !s.getApprovalStatus().equals(ProjectStatusEnum.ARRANGE_REVIEW_TO_BE_REBACK.get().getStatus()) &&
                        !s.getApprovalStatus().equals(ProjectStatusEnum.SCHEME_DECLARATION_SUBMISSION_SUBMITTED.get().getStatus())
        ).collect(Collectors.toList());
        collect.stream().forEach(s-> {
                    List<YzqFile> fileList = new ArrayList<>();
                    ApprovalVo approvalVo = new ApprovalVo();
                    BeanUtils.copyProperties(s, approvalVo);
                    approvalVo.setApprovalStatusName(ProjectStatusEnum.getEnum(approvalVo.getApprovalStatus()).getStatusDes());
                    if (StringUtils.isNotNull(approvalVo.getApprovalDatabase())) {
                        if (approvalVo.getApprovalDatabase().contains(",")) {
                            List<String> fileNameList = new ArrayList<String>();
                            StringTokenizer st = new StringTokenizer(approvalVo.getApprovalDatabase(), ",");
                            while (st.hasMoreTokens()) {
                                String s1 = st.nextToken();
                                YzqFile yzqFile = fileService.getById(s1);
                                if (StringUtils.isNotNull(yzqFile)) {
                                    fileList.add(yzqFile);
                                    String fileName = yzqFile.getFileName();
                                    if (StringUtils.isNotEmpty(fileName)) {
                                        fileNameList.add(fileName);
                                    }

                                }
                            }
                            approvalVo.setApprovalDatabaseName(String.join(";", fileNameList));
                        } else {
                            YzqFile file = fileService.getById(approvalVo.getApprovalDatabase());
                            if (file != null) {
                                fileList.add(file);
                                approvalVo.setApprovalDatabaseName(file.getFileName());
                            }

                        }
                        approvalVo.setRelationFile(fileList);
                    }
        });
        List<ApprovalVo> approvalVoList = getApprovalVoList(collect);
        thirdVo.setApprovalList(approvalVoList);

        if (projectInfo.getNature().equals("0")) {
            //加入年度申报
            AnnualDeclaration annulInfo = annualDeclarationMapper.selectById(projectInfo.getAnnualId());
            Assert.isTrue(StringUtils.isNotNull(annulInfo)&&  !annulInfo.getDelFlag().equals("1"),
                    "年度申报不存在!!!");
            //同步文件
            YzqFile filePP = fileService.getById(annulInfo.getProjectProposal());
            AnnualDeclarationVo annualDeclarationVo = new AnnualDeclarationVo();
            BeanUtils.copyProperties(annulInfo,annualDeclarationVo);
            annualDeclarationVo.setProjectProposalFile(filePP);
            thirdVo.setAnnualDeclarationVo(annualDeclarationVo);
        }else if (projectInfo.getNature().equals("1")){
            //增补项目
            SupplementaryDeclaration supplementaryInfo = supplementaryDeclarationMapper.selectById(projectInfo.getSupplementaryId());
            Assert.isTrue(StringUtils.isNotNull(supplementaryInfo)&&!supplementaryInfo.getDelFlag().equals("1"),
                    "增补申报不存在！！！");
            //同步文件
            YzqFile filePP = fileService.getById(supplementaryInfo.getProjectProposal());
            YzqFile fileSv = fileService.getById(supplementaryInfo.getSupplementaryVoucher());
            SupplementaryDeclarationVo supplementaryDeclarationVo = new SupplementaryDeclarationVo();
            BeanUtils.copyProperties(supplementaryInfo,supplementaryDeclarationVo);
            supplementaryDeclarationVo.setProjectProposalFile(filePP);
            supplementaryDeclarationVo.setSupplementaryVoucherFile(fileSv);
            thirdVo.setSupplementaryDeclarationVo(supplementaryDeclarationVo);
        }

        //加入方案申报
        SchemeDeclaration schemeInfo = schemeDeclarationMapper.selectSchemeDeclarationByProgrammeId(projectInfo.getProgrammeId());
        Assert.isTrue(StringUtils.isNotNull(schemeInfo)&& !schemeInfo.getDelFlag().equals("1"),"" +
                "方案申报不存在!!!");
        //方案同步文件
        SchemeDeclarationVo schemeDeclarationVo = new SchemeDeclarationVo();
        BeanUtils.copyProperties(schemeInfo,schemeDeclarationVo);
        if(StringUtils.isNotNull(schemeInfo)){
            YzqFile fileRR = fileService.getById(schemeInfo.getResearchReport());
            YzqFile fileBP = fileService.getById(schemeInfo.getBudgetProposal());
            YzqFile fileBPm = fileService.getById(schemeInfo.getBudgetProgramme());
            YzqFile filePD = fileService.getById(schemeInfo.getPreliminaryDesignScheme());
            YzqFile fileCra = fileService.getById(schemeInfo.getCloudResourceApplication());

            BeanUtils.copyProperties(schemeInfo,schemeDeclarationVo);
            schemeDeclarationVo.setResearchReportFile(fileRR);
            schemeDeclarationVo.setBudgetProposalFile(fileBP);
            schemeDeclarationVo.setBudgetProgrammeFile(fileBPm);
            schemeDeclarationVo.setPreliminaryDesignSchemeFile(filePD);
            schemeDeclarationVo.setCloudResourceApplicationFile(fileCra);
        }
        thirdVo.setSchemeDeclarations(schemeDeclarationVo);
        List<SystemInfoVo> systemInfoVos = systemInfoService.selectSystemInfoListByProgrammeIds(schemeInfo.getProgrammeId());
        List<SystemInfoVo> arrayList = new ArrayList<>();
        systemInfoVos.stream().forEach(s->{
            SystemInfoVo systemInfoVo = new SystemInfoVo();
            BeanUtils.copyProperties(s,systemInfoVo);
            List<ProjectSystemInfo> list = projectSystemInfoService.lambdaQuery().eq(ProjectSystemInfo::getAppName, s.getSystemName()).list();
            if(StringUtils.isNotEmpty(list)){
                if(list.get(0).getAppIsCloud()){
                    systemInfoVo.setAppIsCloud("1");
                }else {
                    systemInfoVo.setAppIsCloud("0");
                }

            }else {
                systemInfoVo.setAppIsCloud("0");
            }
            arrayList.add(systemInfoVo);
        });
        thirdVo.setSystemInfoVoList(arrayList);
        QueryWrapper<GovernmentDataResources> governmentQueryWrapper = new QueryWrapper<>();
        governmentQueryWrapper.eq("programme_id",schemeInfo.getProgrammeId());
        governmentQueryWrapper.eq("del_flag","0");
        List<GovernmentDataResources> governmentList = governmentDataResourcesService.list(governmentQueryWrapper);
        thirdVo.setGovernmentDataResourcesVoList(governmentList);
        List<CloudResourceRequirementVo> cloudResourceRequirementVo =  cloudResourceRequirementService.selectCloudResourceListByProgrammeIds(schemeInfo.getProgrammeId());
        thirdVo.setCloudResourceRequirementVoList(cloudResourceRequirementVo);
        List<IotDeviceInfoVo> iotDeviceInfoVo = iotDeviceInfoService.selectDeviceInfoListByProgrammeIds(schemeInfo.getProgrammeId());
        thirdVo.setIotDeviceInfoVoList(iotDeviceInfoVo);
        //返回项目id和最新审核阶段
        thirdVo.setProjectId(projectInfo.getProId());
        thirdVo.setApprovalNode(projectInfo.getNode());
        thirdVo.setApprovalStage(projectInfo.getStag());
        return thirdVo;
    }

    /**
     * 专家列表查询
     * @param queryExpert 评审任务
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<ReviewTaskExpertListVo> selectExpertList1(QueryReviewTaskExpertDto queryExpert,Integer pageNum,Integer pageSize) {
        //待处理
        ArrayList<String> pendings = new ArrayList<>();
        pendings.add(ExtractExpert.STATUS_NOT_ACCEPT);
        pendings.add(ExtractExpert.STATUS_NOT_APPROVAL);
        //已处理
        ArrayList<String> processeds = new ArrayList<>();
        processeds.add(ExtractExpert.STATUS_REJECT);
        processeds.add(ExtractExpert.STATUS_APPLY_CANCEL);
        processeds.add(ExtractExpert.STATUS_APPLY_ACCEPT);
        processeds.add(ExtractExpert.STATUS_APPLY_APPROVAL);
        processeds.add(ExtractExpert.STATUS_APPLY_APPROVAL_AGREE_CANCEL);
        processeds.add(ExtractExpert.STATUS_NOT_START);
        //已结束
        ArrayList<String> over = new ArrayList<>();
        over.add(ExtractExpert.STATUS_FINISH);

        if (StringUtils.isNotEmpty(queryExpert.getProcessingStatus())){
            switch (queryExpert.getProcessingStatus()){
                case "0":
                    queryExpert.getStatusCollect().addAll(pendings);
                    break;
                case "1":
                    queryExpert.getStatusCollect().addAll(processeds);
                    break;
                case "2":
                    queryExpert.getStatusCollect().addAll(over);
                    break;
            }
        }

        Long userId = SecurityUtils.getUserId();
        QueryWrapper<ExpertInformationSheet> expertInQueryWrapper = new QueryWrapper<>();
        if (SecurityUtils.getUserId().equals(1L)){
            expertInQueryWrapper.eq("del_flag",ExpertInformationSheet.DELETE_STATUS_NORMAL);
        }else{
            expertInQueryWrapper.eq("user_id",userId);
            expertInQueryWrapper.eq("del_flag",ExpertInformationSheet.DELETE_STATUS_NORMAL);
        }
        List<ExpertInformationSheet> expertInfoList = expertInformationSheetMapper.selectList(expertInQueryWrapper);
        System.err.println(expertInfoList);
        Assert.isTrue(expertInfoList.size() > 0,"专家不存在!!!");
        //取出id列表
        List<Long> ids = expertInfoList.stream().map(ExpertInformationSheet::getExpertId).collect(Collectors.toList());
        //转为数组
        Long [] numberIds = ids.toArray(new Long[ids.size()]);
        if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) {
            PageHelper.startPage(pageNum, pageSize);
        }
        List<ReviewTaskExpertListVo> expertListVos = reviewTaskMapper.selectExpertList1(numberIds,queryExpert);
        expertListVos.forEach(s->{
            if (pendings.contains(s.getStatus())){
                s.setProcessingStatus("待处理");
            } else if (processeds.contains(s.getStatus())) {
                s.setProcessingStatus("已处理");
            } else if (over.contains(s.getStatus())) {
                s.setProcessingStatus("已结束");
            }
        });
       return expertListVos;
    }

    /**
     * 三方列表查询
     * @param queryThird
     * @return
     */
    @Override
    public PageInfo selectThirdList(QueryReviewTaskThirdDto queryThird) {
        //待处理
        ArrayList<String> pendings = new ArrayList<>();
        pendings.add(ProjectStatusEnum.ARRANGE_REVIEW_MEETING_TO_BE_EXTRACTED.get().getStatus());
        pendings.add(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_ARRANGE.get().getStatus());
        pendings.add(ProjectStatusEnum.COMMENTS_SUMMARY_TO_BE_APPROVED.get().getStatus());
        pendings.add(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus());
        pendings.add(ProjectStatusEnum.SCHEME_DECLARATION_UPDATE_TO_BE_APPROVED.get().getStatus());
        pendings.add(ProjectStatusEnum.BIG_DATA_AUDIT_SUMMARY_AND_RETURN_OF_COMMENTS.get().getStatus());
        //已处理
        ArrayList<String> processeds = new ArrayList<>();
        processeds.add(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStatus());
        processeds.add(ProjectStatusEnum.SCHEME_DECLARATION_UPDATE_RETURN_MODIFICATION.get().getStatus());
        processeds.add(ProjectStatusEnum.ACCEPT_NOT_TASK.get().getStatus());
        processeds.add(ProjectStatusEnum.BIG_DATA_AUDIT_COMMENTS_SUMMARY_TO_BE_APPROVED.get().getStatus());
        processeds.add(ProjectStatusEnum.BIG_DATA_AUDIT_OPINION_SUMMARY_APPROVED.get().getStatus());
        processeds.add(ProjectStatusEnum.SCHEME_DECLARATION_UPDATE_PASSED.get().getStatus());
        processeds.add(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_TO_BE_REVIEWED.get().getStatus());
        processeds.add(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_HAS_BEEN_PASSED.get().getStatus());
        processeds.add(ProjectStatusEnum.SUMMARY_AND_RETURN_OF_COMMENTS.get().getStatus());
        processeds.addAll(ProjectStatusEnum.getEnumByNode("初设及概算方案批复"));
        processeds.addAll(ProjectStatusEnum.getEnumByNode("合同备案"));
        processeds.addAll(ProjectStatusEnum.getEnumByNode("里程碑管理"));
        processeds.addAll(ProjectStatusEnum.getEnumByNode("合规审查"));
        processeds.addAll(ProjectStatusEnum.getEnumByNode("初验备案"));
        processeds.addAll(ProjectStatusEnum.getEnumByNode("终验备案"));
        processeds.addAll(ProjectStatusEnum.getEnumByNode("绩效考评"));


        if (StringUtils.isNotEmpty(queryThird.getProcessingStatus())) {
            switch (queryThird.getProcessingStatus()){
                case "0":
                    queryThird.setStatusCollect(pendings);
                    break;
                case "1":
                    queryThird.setStatusCollect(processeds);
                    break;
            }
        }
        List<SysRole> roles = SecurityUtils.getLoginUser().getUser().getRoles();
        List<Long> collect = roles.stream().map(SysRole::getRoleId).collect(Collectors.toList());
        Assert.isTrue(collect.contains(Constants.ROLE_TYPE_THIRD),"账号不是三方账号，请更换账号登录!!!");
        QueryWrapper<OrganizationManagement> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dept_id",SecurityUtils.getDeptId())
                .eq("is_delete",Constants.DELETE_STATUS_NORMAL);
        OrganizationManagement organizationManagement = organizationManagementService.getOne(queryWrapper);
        queryThird.setOrmId(organizationManagement.getOrmId());
        startPage();
        List<ReviewTaskThirdListVo> thirdListVo = reviewTaskMapper.selectThirdList(queryThird,"0");
        //三方查看任务节点只到大数据局审核
        thirdListVo.forEach(s->{
            s.setNodeName(ProjectStatusEnum.getEnum(s.getNodeStatus()).getStatusDes());
            if (pendings.contains(s.getNodeStatus())){
                s.setNodeName("待处理");
            } else if (processeds.contains(s.getNodeStatus())) {
                s.setNodeName("已处理");
            }
            if (Integer.parseInt(s.getNodeStatus()) >= (Integer.parseInt(ProjectStatusEnum.FINANCIAL_APPROVAL_AND_FILING_TO_BE_REVIEWED.get().getStatus()))
                    && Integer.parseInt(s.getNodeStatus()) <= (Integer.parseInt(ProjectStatusEnum.PERFORMANCE_EVALUATION_HAS_BEEN_EVALUATED.get().getStatus()))) {
                s.setNode(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_HAS_BEEN_PASSED.get().getNode());
                s.setNodeName("已处理");
                s.setNodeStatus(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_HAS_BEEN_PASSED.get().getStatus());
            }

        });
        return new PageInfo(thirdListVo);
    }


    /**
     * 新增评审任务
     *
     * @param addDto 评审任务
     * @return 结果0
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long insertReviewTask(InsertReviewTaskDto addDto){
        List<ExtractRuleDto> expertList = addDto.getExpertList();
        Long reviewTaskId ;
        String projectName;
        List<ExtractMonitoring> list = new ArrayList<>();
        //项目的方案评审 需项目id
        if(ReviewTask.REVIEW_TYPE_PROGRAMME.equals(addDto.getReviewType())){
            ProjectManagement projectManagement = projectManagementService.getById(addDto.getProId());
            Assert.isTrue(StringUtils.isNotNull(projectManagement),"未找到该项目");
            projectName=projectManagement.getName();
            if(StringUtils.isNotNull(projectManagement.getReviewTaskId())){
                ReviewTask reviewTask = reviewTaskMapper.selectById(projectManagement.getReviewTaskId());
                Assert.isTrue(StringUtils.isNotNull(reviewTask),"移交第三方的评审任务为空");
                //转移第三方项目中评审id字段不为空
                if(reviewTask.getIfExchangeThird().equals(ReviewTask.IF_EXCHANGE_THIRD_YES)){
                    BeanUtils.copyProperties(addDto,reviewTask);
                    reviewTask.setNodeStatus(Constants.ARRANGE_REVIEW_MEETING_BAND_EXTRACTION);
                    reviewTask.setNode(ProjectStatusEnum.ACCEPT_NOT_TASK.get().getNode());
                    reviewTask.setExtractTime(LocalDateTime.now());
                    reviewTask.setExpertStatus(ReviewTask.EXTRACT_STATUS_NOT_ACCEPT);
                    reviewTask.setExtractType(ReviewTask.EXTRACT_TYPE_UNIFY);
                    reviewTask.setExtractResult(ReviewTask.EXTRACT_RESULT_SEND_EXPERT);
                    //抽取单位
                    reviewTask.setExtractUnit(String.valueOf(SecurityUtils.getDeptId()));
                    //抽取操作人
                    SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
                    reviewTask.setExtractPeople(sysUser.getNickName());
                    reviewTaskMapper.updateById(reviewTask);
                    reviewTaskId=reviewTask.getReviewTaskId();
                    //新增评审任务
                }else {
                    ReviewTask reviewTaskRoll = InsertReviewTaskDto.toReviewTask(addDto);
                    reviewTaskId=reviewTaskRoll.getReviewTaskId();
                    reviewTaskMapper.insert(reviewTaskRoll);
                    projectManagement.setReviewTaskId(reviewTaskRoll.getReviewTaskId());
                }

                //未转移
            }else {
                ReviewTask reviewTask = InsertReviewTaskDto.toReviewTask(addDto);
                reviewTaskId=reviewTask.getReviewTaskId();
                reviewTaskMapper.insert(reviewTask);
                //更新项目状态为接受任务 待审核
                projectManagement.setReviewTaskId(reviewTask.getReviewTaskId());
            }
            //更新进程为安排评审会议-已抽取专家
            approvalService.dealStayApproval(addDto.getProId(),ProjectStatusEnum.ARRANGE_REVIEW_MEETING_TO_BE_EXTRACTED.get().getStatus(),ProjectStatusEnum.ARRANGE_REVIEW_TO_BE_ACCEPTED.get().getStatus(),null,null,null,SecurityUtils.getNickName());
            //新增接受任务节点进程
            approvalService.save(new Approval(IdUtils.snowId(),projectManagement.getProId(),ProjectStatusEnum.ACCEPT_NOT_TASK.get().getStage(),
                    ProjectStatusEnum.ACCEPT_NOT_TASK.get().getNode(),LocalDateTime.now(),null,null,ProjectStatusEnum.ACCEPT_NOT_TASK.get().getStatus(),
                    "/",null, null,null, LocalDateTime.now(),Approval.APPROVAL_TYPE_PROJECT_MANAGE));
            //更新项目状态为接受任务 待接收任务
            projectManagement.setIsState(ProjectStatusEnum.ACCEPT_NOT_TASK.get().getStatus());
            projectManagement.setStag(ProjectStatusEnum.ACCEPT_NOT_TASK.get().getStage());
            projectManagement.setNode(ProjectStatusEnum.ACCEPT_NOT_TASK.get().getNode());
            projectManagementService.updateById(projectManagement);
            //同步项目数据到项目信息表中
            approvalService.synchronizationProjectInfo(projectManagement);
            //年度抽取监控记录
            List<ExtractMonitoring> monitoringList = extractMonitoringService.lambdaQuery().eq(ExtractMonitoring::getProId, addDto.getProId()).list();
            list.addAll(monitoringList);
            //年度的方案评审
        }else {
            List<ProjectManagement> projectManagementList = projectManagementService.lambdaQuery().eq(ProjectManagement::getPlanId, addDto.getPlanId())
                    .eq(ProjectManagement::getIsDelete, ExtractExpert.DELETE_STATUS_NORMAL).list();
            Assert.isTrue(StringUtils.isNotEmpty(projectManagementList),"该年度计划下没有年度申报");
            List<ProjectManagement> collect = projectManagementList.stream().filter(s -> s.getIsState().equals(ProjectStatusEnum.DECLARATION_SUBMISSION_SUBMITTED.get().getStatus())).collect(Collectors.toList());
            List<ReviewTask> reviewTaskList = reviewTaskService.lambdaQuery().eq(ReviewTask::getPlanId, addDto.getPlanId())
                    .eq(ReviewTask::getDelFlag, ExtractExpert.DELETE_STATUS_NORMAL).list();
            Assert.isTrue(StringUtils.isEmpty(reviewTaskList),"该年度计划已有年度评审任务");
            ReviewTask reviewTask = InsertReviewTaskDto.toReviewTask(addDto);
            reviewTaskId=reviewTask.getReviewTaskId();
            Assert.isTrue(StringUtils.isNotNull(addDto.getPlanId()),"年度计划的评审，年度id不能为空");
            AnnualProjectPlan projectPlan = annualProjectPlanService.getById(addDto.getPlanId());
            Assert.isTrue(StringUtils.isNotNull(projectPlan),"未找到该年度计划");
            projectName=projectPlan.getName();
            reviewTask.setPlanId(addDto.getPlanId());
            reviewTask.setNodeStatus(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus());
            reviewTask.setNode(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getNode());
            reviewTaskMapper.insert(reviewTask);
            //年度抽取监控记录
            List<ExtractMonitoring> monitoringList = extractMonitoringService.lambdaQuery().eq(ExtractMonitoring::getPlanId, addDto.getPlanId()).list();
            list.addAll(monitoringList);
        }

        List<Long> extractIdList = new ArrayList<>();
        List<Long> extractExpertIdList = new ArrayList<>();
        List<ExtractRule> extractRuleList = new ArrayList<>();
        List<ExtractExpert> extractExpertList = new ArrayList<>();
        List<String> expertNameList = new ArrayList<>();
        List<ExtractRuleDto> voList = addDto.getExpertList();
        voList.forEach(s->{
            //抽取的规则去重
            expertNameList.add(s.getExpertName());
            if (!extractIdList.contains(s.getExtractRuleId())){
                ExtractRule extractRule = new ExtractRule();
                extractRule.setReviewId(reviewTaskId);
                extractRule.setExtractId(s.getExtractRuleId());
                extractRule.setExtractType(s.getExtractType());
                extractRule.setPeopleNumber(s.getPeopleNumber());
                extractRule.setExtractRuleDesc(s.getExtractRuleDesc());
                extractRuleList.add(extractRule);
                extractIdList.add(s.getExtractRuleId());
            }
            //抽取出来的专家信息
            ExtractExpert extractExpert = new ExtractExpert();
            extractExpert.setExtractExpertId(IdUtils.snowId());
            extractExpert.setExchangeNum(ExtractExpert.APPLY_NOT_CANCEL);
            extractExpert.setExpertId(s.getExpertId());
            extractExpert.setExtractNode(ProjectStatusEnum.ACCEPT_NOT_TASK.get().getStatus());
            extractExpert.setExtractRuleId(s.getExtractRuleId());
            extractExpert.setStatus(ExtractExpert.STATUS_NOT_ACCEPT);
            extractExpert.setDelFlag(ExtractExpert.DELETE_STATUS_NORMAL);
            extractExpert.setCreateTime(LocalDateTime.now());
            extractExpert.setReceiveStatus(ExtractExpert.RECEIVE_STATUS_TO_BE_ACCEPT);
            extractExpert.setApplyCancel(ExtractExpert.APPLY_NOT_CANCEL);
            extractExpertIdList.add(extractExpert.getExtractExpertId());
            extractExpertList.add(extractExpert);
        });
        //所有抽取出的专家新增待接受任务审核进程
        List<Approval> approvalList = new ArrayList<>();
        extractExpertList.stream().forEach(s->{
            Approval approval = new Approval(IdUtils.snowId(),addDto.getProId()!=null?addDto.getProId():null,ProjectStatusEnum.ACCEPT_NOT_TASK.get().getStage(),
                    ProjectStatusEnum.ACCEPT_NOT_TASK.get().getNode(),LocalDateTime.now(),LocalDateTime.now(),SecurityUtils.getNickName(),ProjectStatusEnum.ACCEPT_NOT_TASK.get().getStatus(),
                    "/",null, null,null, LocalDateTime.now(), Approval.APPROVAL_TYPE_EXPERT,s.getExpertId(),addDto.getPlanId()!=null?addDto.getPlanId():null);
            approvalList.add(approval);
            //todo 对接短信接口
            ExpertInformationSheet expertInfo = expertInformationSheetService.getById(s.getExpertId());
            if(StringUtils.isNotNull(expertInfo)){
                if(StringUtils.isNotEmpty(expertInfo.getPhoneNumber())){
                    Assert.isTrue(StringUtils.isNotNull(expertInfo.getUserId()),expertInfo.getExpertName()+"专家未绑定用户!请绑定用");
                    CodeVo code = NoteConfig.getCode();
                    String content= NoteConfig.TITLE+expertInfo.getExpertName()+NoteConfig.EXPORTS+projectName+NoteConfig.TASK_PROJECT+code.getCode()+NoteConfig.TASK_MASSAGE+NoteConfig.createH5(String.valueOf(reviewTaskId),code.getUuid(),String.valueOf(expertInfo.getUserId()));
//                    NoteConfig.getNote(content,expertInfo.getPhoneNumber());
                }
            }
        });
        //批量插入专家的审核进程
        approvalService.batchApproval(approvalList);
        //批量插入抽取规则
        extractRuleService.batchInsert(extractRuleList);
        //批量插入抽取专家list
        extractExpertService.batchInsertExtractExpert(extractExpertList);
        //批量插入评审任务与抽取专家关系
        extractReviewService.batchInsertExtractReview(reviewTaskId,extractExpertIdList);
        //生成一条专家确认进程
        String username = SecurityUtils.getNickName();
        String content="抽取专家:";
        expertCourseService.save(new ExpertCourse(IdUtils.snowId(),reviewTaskId,username+
                content.concat(String.join("、", expertNameList)),LocalDateTime.now()));
        //新增评审任务的抽取监控
        Assert.isTrue(StringUtils.isNotEmpty(list),"未找到相应的抽取监控信息");
        list.stream().forEach(s->{
            s.setReviewTaskId(reviewTaskId);
            s.setTaskName(addDto.getTaskName());
            s.setExtractResult(ExtractMonitoring.EXTRACT_TYPE_EXCHANGE);
        });
        //新增评审任务：最新的一条抽取监控抽取结果为发送专家接受
        list.sort(Comparator.comparing(ExtractMonitoring::getExtractTime).reversed());
        list.get(0).setExtractResult(ExtractMonitoring.EXTRACT_TYPE_UNIFY);
        extractMonitoringService.saveOrUpdateBatch(list);
        return reviewTaskId;
    }
    /**
     * 查看评审任务详情（项目id查）
     *
     * @param projectId 查看评审任务详情
     * @return 评审任务
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ReviewTaskDetailVo reviewTaskDetailByProId(Long projectId) {
        Long reviewTaskId = projectManagementService.selectProjectManagementByProId(projectId).getReviewTaskId();
        return reviewTaskMapper.reviewTaskDetailById(reviewTaskId);
    }
    /**
     * 查看评审任务详情（评审任务id查）
     *
     * @param reviewTaskId 查看评审任务详情
     * @return 评审任务
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ReviewTaskDetailVo reviewTaskDetailByTaskId(Long reviewTaskId) {
        ReviewTaskDetailVo reviewTaskDetailVo = reviewTaskMapper.reviewTaskDetailById(reviewTaskId);
        List<ExtractExpertDetailVo> extractExpertList = reviewTaskDetailVo.getExtractExpertList();
        if(StringUtils.isNotEmpty(extractExpertList)){
            extractExpertList.stream().forEach(s->{
                List<String> technicalList = new ArrayList<>();
                //返回专家技术职称
                List<TechnicalTitle> technicalTitleList = technicalTitleService.lambdaQuery().eq(TechnicalTitle::getExpertId, s.getExpertId()).list();
                if(StringUtils.isNotEmpty(technicalTitleList)){
                    List<String> technicalCollect = technicalTitleList.stream().map(TechnicalTitle::getJobTitle).collect(Collectors.toList());

                    technicalCollect.stream().forEach(a->{
                        technicalList.add(dictDataService.selectDictLabel("technical_type", a));
                    });
                }
                s.setTechnicalName(StringUtils.join(technicalList,","));
                //擅长领域
                if(StringUtils.isNotEmpty(s.getAreasOfExpertise())){
                    s.setAreasOfExpertise(dictDataService.selectDictLabel("areas_of_expertise", s.getAreasOfExpertise()));
                }
            });
        }
        return reviewTaskDetailVo;
    }
    /**
     * 查看评审任务详情（年度计划id查）
     *
     * @param planId 查看评审任务详情
     * @return 评审任务
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ReviewTaskDetailVo reviewTaskDetailByPlanId(Long planId) {
        LambdaQueryWrapper<ReviewTask> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ReviewTask::getPlanId, planId)
                .eq(ReviewTask::getReviewType, "1")
                .select(ReviewTask::getReviewTaskId);
        ReviewTask reviewTask = reviewTaskMapper.selectOne(queryWrapper);
        return reviewTaskMapper.reviewTaskDetailById(reviewTask.getReviewTaskId());
    }

    /**
     * 大数据局查询评审任务列表
     *
     * @param dto 评审任务
     * @return 评审任务
     */

    @Override
    public List<ReviewTaskListVo> selectReviewTaskList(ReviewTaskDto dto) {
        return reviewTaskMapper.selectReviewTaskList(dto);
    }


    /**
     * 修改评审任务
     *
     * @param updateDto 评审任
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateReviewTask(UpdateReviewTaskDto updateDto) {
        Assert.isTrue(StringUtils.isNotNull(updateDto.getReviewTaskId()),"评审任务id为空");
        ReviewTask reviewTask = reviewTaskMapper.selectById(updateDto.getReviewTaskId());
        BeanUtils.copyProperties(updateDto,reviewTask);
        return reviewTaskMapper.updateById(reviewTask);
    }

    /**
     * 删除评审任务信息
     *
     * @param reviewTaskId 评审任务主键
     * @return 结果
     */
    @Override
    public int deleteReviewTaskByReviewTaskId(Long reviewTaskId)
    {
        ReviewTask reviewTask = reviewTaskMapper.selectById(reviewTaskId);
        Assert.isTrue(StringUtils.isNotNull(reviewTask),"评审任务为空");
        Assert.isTrue(!reviewTask.getNode().equals(ProjectStatusEnum.PERFORMANCE_EVALUATION_HAS_BEEN_EVALUATED),"项目节点未到绩效考评不能删除");
        reviewTask.setDelFlag(ExtractExpert.DELETE_STATUS_DELETED);
        return reviewTaskMapper.updateById(reviewTask);
    }
    /**
     * 专家删除对应的评审任务
     *
     * @param reviewTaskId 评审任务主键
     * @param expertId 专家id
     * @return 结果
     */
    @Override
    public boolean removeExpert(Long reviewTaskId,Long expertId)
    {
        ExtractExpert extractExpert = reviewTaskMapper.extractExpertByReviewTaskId(reviewTaskId, expertId);
        Assert.isTrue(StringUtils.isNotNull(extractExpert),"未找到该评审下的专家抽取信息");
        extractExpert.setDelFlag(ExtractExpert.DELETE_STATUS_DELETED);
        return extractExpertService.updateById(extractExpert);
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int exchangeThird(String taskName,Long proId,Long ormId) {
        List<Approval> approvalTask = approvalService.lambdaQuery().eq(Approval::getApprovalNode, ProjectStatusEnum.TURN_SENT_TASK.get().getNode())
                .eq(Approval::getProjectId, proId)
                .eq(Approval::getDelFlag, Constants.DELETE_STATUS_NORMAL).list();
        Assert.isTrue(StringUtils.isEmpty(approvalTask),"该项目已转派三方！");
        OrganizationManagement organizationManagement = organizationManagementService.selectOrganizationManagementByOrmId(ormId);
        Assert.isTrue(StringUtils.isNotNull(organizationManagement),"未找到该机构");
        ProjectManagement projectManagement = projectManagementService.getById(proId);
        Assert.isTrue(StringUtils.isNotNull(projectManagement),"未找到该项目");
        Assert.isTrue(StringUtils.isNull(projectManagement.getReviewTaskId()),"该项目已经转第三方管理或已有评审任务！");
        ReviewTask reviewTask = new ReviewTask();
        reviewTask.setNode(ProjectStatusEnum.ARRANGE_REVIEW_MEETING_TO_BE_EXTRACTED.get().getNode());
        reviewTask.setNodeStatus(Constants.ARRANGE_REVIEW_MEETING_TO_BE_EXTRACTED);
        reviewTask.setIfExchangeThird(ReviewTask.IF_EXCHANGE_THIRD_YES);
        reviewTask.setOrmId(ormId);
        reviewTask.setDelFlag(ExtractExpert.DELETE_STATUS_NORMAL);
        reviewTask.setCreateTime(LocalDateTime.now());
        reviewTask.setReviewTaskId(IdUtils.snowId());
        reviewTask.setTaskName(taskName);
        reviewTask.setReviewType(ReviewTask.REVIEW_TYPE_PROGRAMME);
        projectManagement.setReviewTaskId(reviewTask.getReviewTaskId());
        projectManagement.setTripartiteId(ormId);
        projectManagementService.updateById(projectManagement);
        int result = reviewTaskMapper.insert(reviewTask);
        Assert.isTrue(result > 0,"转三方失败!!!");
        ProjectManagementDetailsVo projectManagementDetailsVo = projectManagementService.selectProjectManagementListByReviewIds(reviewTask.getReviewTaskId());
        Assert.isTrue(StringUtils.isNotNull(projectManagementDetailsVo),"未找到该项目信息");
        Approval approval = approvalService.getApproval(projectManagementDetailsVo.getProId(), ProjectStatusEnum.ARRANGE_REVIEW_MEETING_TO_BE_EXTRACTED.get().getStatus(), null, null);
        LocalDateTime localDateTime = LocalDateTime.now();
        if (approval.getCreateTime().getSecond() == 0) {
            localDateTime=LocalDateTime.of(approval.getCreateTime().getYear(),approval.getCreateTime().getMonth(),approval.getCreateTime().getDayOfMonth(),approval.getCreateTime().getHour(),approval.getCreateTime().getMinute()-1,59);
        }else{
            localDateTime=LocalDateTime.of(approval.getCreateTime().getYear(),approval.getCreateTime().getMonth(),approval.getCreateTime().getDayOfMonth(),approval.getCreateTime().getHour(),approval.getCreateTime().getMinute(),approval.getCreateTime().getSecond()-1);
        }

        //转三方新增一个审核进度 -- 转派任务
        approvalService.save(new Approval(IdUtils.snowId(),reviewTask.getReviewTaskId(),projectManagementDetailsVo==null?null:projectManagementDetailsVo.getProId(),
                Approval.APPROVAL_TYPE_THIRD,"",ProjectStatusEnum.TURN_SENT_TASK.get().getNode(),LocalDateTime.now(),LocalDateTime.now(),SecurityUtils.getNickName(),
                ProjectStatusEnum.TURN_SENT_TASK.get().getStatus(),"/","","","",
                Approval.DELETE_STATUS_NORMAL,localDateTime,LocalDateTime.now()
                ,null,null));
        //修改安排评审会议进程创建时间
        approval.setStartTime(LocalDateTime.now());
        approvalService.updateById(approval);
        // todo 去抽取专家操作
        return  result;
    }
    /**
     * 查询抽取专家监控详情
     * @param reviewTaskId
     * @return
     */
    @Override
    public ExpertExtractMonitorDetailVo selectExpertExtractMonitorById(Long reviewTaskId,String extractTime) {
        ExpertExtractMonitorDetailVo expertExtractMonitorDetailVo = new ExpertExtractMonitorDetailVo();
        //监控详情评审任务信息
        ReviewTask reviewTask = reviewTaskService.getById(reviewTaskId);
        BeanUtils.copyProperties(reviewTask,expertExtractMonitorDetailVo);
        //监控详情专家信息
        List<ExtractMonitoring> list = extractMonitoringService.lambdaQuery().eq(ExtractMonitoring::getReviewTaskId, reviewTaskId)
                .eq(ExtractMonitoring::getExtractTime,extractTime).list();
        Assert.isTrue(StringUtils.isNotEmpty(list),"未找到该抽取信息");
        ExtractMonitoring extractMonitoring = list.get(0);
        String expertInformation = extractMonitoring.getExpertInformation();
        List<ExtractRuleBeginVo> extractExpertList=new ArrayList<>();
        if(ExtractMonitoring.EXTRACT_TYPE_UNIFY.equals(extractMonitoring.getExtractType())){
            extractExpertList = JSON.parseArray(expertInformation, ExtractRuleBeginVo.class);
        }else {
            if(expertInformation.contains("[")){
                expertInformation=expertInformation.replace("[","");
                expertInformation=expertInformation.replace("]","");
            }
            JSONObject obj= JSONObject.parseObject(expertInformation);
            String expertId = obj.getString("expertId");
            ExtractRuleBeginVo beginVo = new ExtractRuleBeginVo();
            beginVo.setExpertId(Long.valueOf(expertId));
            extractExpertList.add(beginVo);
        }
        List<ExtractExpertInfoVo> expertInfoVoList= new ArrayList<>();
        extractExpertList.stream().forEach(s -> {
            ExtractExpertInfoVo extractExpertInfoVo = new ExtractExpertInfoVo();
            BeanUtils.copyProperties(s,extractExpertInfoVo);
            //返回对应职称
            List<TechnicalTitle> technicalTitleList = technicalTitleService.lambdaQuery().eq(TechnicalTitle::getExpertId, s.getExpertId()).list();
            if (StringUtils.isNotEmpty(technicalTitleList)) {
                List<String> collect = technicalTitleList.stream().map(TechnicalTitle::getJobTitle).collect(Collectors.toList());
                List<String> technicalList = new ArrayList<>();
                collect.stream().forEach(a -> {
                    technicalList.add(dictDataService.selectDictLabel("technical_type", a));
                });
                extractExpertInfoVo.setTechnicalName(StringUtils.join(technicalList, ","));
            }
            expertInfoVoList.add(extractExpertInfoVo);
        });
        expertExtractMonitorDetailVo.setExtractExpertInfoVos(expertInfoVoList);
        //监控详情抽取信息
        BeanUtils.copyProperties(extractMonitoring,expertExtractMonitorDetailVo);
        expertExtractMonitorDetailVo.setExpertNum(extractMonitoring.getExtractNum());
        SysDept sysDept = deptService.selectDeptById(Long.valueOf(extractMonitoring.getExtractUnit()));
        expertExtractMonitorDetailVo.setExtractUnit(sysDept.getDeptName());
        //监控详情规则信息
        List<ExtractRuleBeginVo> ruleBeginVoList=new ArrayList<>();
        if(ExtractMonitoring.EXTRACT_TYPE_UNIFY.equals(extractMonitoring.getExtractType())){
             ruleBeginVoList = JSON.parseArray(extractMonitoring.getRuleInformation(), ExtractRuleBeginVo.class);
        }else {
            String ruleInformation = extractMonitoring.getRuleInformation();
            if(ruleInformation.contains("[")){
                ruleInformation=expertInformation.replace("[","");
                ruleInformation=expertInformation.replace("]","");
            }
            JSONObject obj= JSONObject.parseObject(ruleInformation);
            String extractType = obj.getString("extractType");
            String extractRuleDesc = obj.getString("extractRuleDesc");
            ExtractRuleBeginVo beginVo = new ExtractRuleBeginVo();
            beginVo.setExtractType(extractType);
            beginVo.setExtractRuleDesc(extractRuleDesc!=null?extractRuleDesc:null);
            ruleBeginVoList.add(beginVo);
        }
        List<ExtractRule> extractRuleList = new ArrayList<>();
        ruleBeginVoList.stream().forEach(s->{
            ExtractRule extractRule = new ExtractRule();
            BeanUtils.copyProperties(s,extractRule);
            extractRuleList.add(extractRule);
        });
        //更换专家-专家信息
        if(extractExpertList.size()==1){
            //返回专家信息
            ExtractRuleBeginVo beginVo1 = extractExpertList.get(0);
            ExtractExpertInfoVo extractExpertInfoVo=new ExtractExpertInfoVo();
            List<ExtractExpertInfoVo> expertInfoVoList1= new ArrayList<>();
            List<ExtractRuleBeginVo> extractRuleBeginVos = expertInformationSheetService.selectListById(Arrays.asList(beginVo1.getExpertId()));
            ExtractRuleBeginVo beginVo = extractRuleBeginVos.get(0);
            extractExpertInfoVo.setExpertId(beginVo.getExpertId());
            extractExpertInfoVo.setExpertName(beginVo.getExpertName());
            extractExpertInfoVo.setSex(beginVo.getSex());
            extractExpertInfoVo.setAge(beginVo.getAge());
            extractExpertInfoVo.setWorkUnit(beginVo.getWorkUnit());
            extractExpertInfoVo.setAreasOfExpertise(dictDataService.selectDictLabel("areas_of_expertise", beginVo.getAreasOfExpertise()));
            expertInfoVoList1.add(extractExpertInfoVo);
            //返回对应职称
            List<TechnicalTitle> technicalTitleList = technicalTitleService.lambdaQuery().eq(TechnicalTitle::getExpertId, beginVo.getExpertId()).list();
            if (StringUtils.isNotEmpty(technicalTitleList)) {
                List<String> collect = technicalTitleList.stream().map(TechnicalTitle::getJobTitle).collect(Collectors.toList());
                List<String> technicalList = new ArrayList<>();
                collect.stream().forEach(a -> {
                    technicalList.add(dictDataService.selectDictLabel("technical_type", a));
                });
                extractExpertInfoVo.setTechnicalName(StringUtils.join(technicalList, ","));
            }
            expertExtractMonitorDetailVo.setExtractExpertInfoVos(expertInfoVoList1);
            //补充返回的规则信息
            ExtractRule extractRule = extractRuleList.get(0);
            extractRule.setPeopleNumber(1);
            //补充返回的抽取信息
            expertExtractMonitorDetailVo.setExpertNum("1");
        }
        expertExtractMonitorDetailVo.setExtractRules(extractRuleList);
        return expertExtractMonitorDetailVo;
    }

    /**
     * 查询专家抽取监控列表
     * @param queryDto
     * @return
     */
    @Override
    public List<ExpertExtractionMonitorListVo> selectExpertExtractMonitorList(QueryExpertExtractMonitorDto queryDto) {
        return expertExtractMonitorMapper.selectExpertExtractMonitorList(queryDto);
    }

    @Override
    @Transactional(rollbackFor=Exception.class)
    public boolean applyCancel(Long reviewTaskId,String applyReason) {
        ReviewTask reviewTask = reviewTaskService.getById(reviewTaskId);
        Assert.isTrue(StringUtils.isNotNull(reviewTask),"未找到该评审任务");
        Long userId = SecurityUtils.getUserId();
        QueryWrapper<ExpertInformationSheet> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        ExpertInformationSheet expertInfo = expertInformationSheetService.getOne(queryWrapper);
        ExtractExpert extractExpert = reviewTaskMapper.extractExpertByReviewTaskId(reviewTaskId, expertInfo.getExpertId());
        Assert.isTrue(extractExpert.getStatus().equals(ExtractExpert.STATUS_NOT_APPROVAL) ||
                extractExpert.getStatus().equals(ExtractExpert.STATUS_NOT_START),"状态为待审核或者待开始才能申请取消！");
        Assert.isTrue(!reviewTask.getNode().equals(ProjectStatusEnum.COMMENTS_SUMMARY_TO_BE_APPROVED.get().getNode()),"项目为在意见汇总时不能申请取消！");
        //更新评审任务
        reviewTask.setExpertStatus(ReviewTask.EXTRACT_STATUS_CANCEL);
        reviewTask.setUpdateTime(LocalDateTime.now());
        ProjectManagementDetailsVo projectManagement = projectManagementService.selectProjectManagementListByReviewIds(reviewTaskId);
        extractExpert.setApplyCancelStatus(extractExpert.getStatus());
        extractExpert.setApplyReason(applyReason);
        extractExpert.setApplyCancel(ExtractExpert.APPLY_CANCEL);
        extractExpert.setStatus(ExtractExpert.STATUS_APPLY_CANCEL);
        extractExpert.setReceiveStatus(ExtractExpert.RECEIVE_STATUS_CANCEL);
        //最新一条专家审核进程(有可能是多个在线预审、重新预审中的一个)更新结束时间
        if(ReviewTask.REVIEW_TYPE_PROGRAMME.equals(reviewTask.getReviewType())){
            //方案
            List<Approval> approvalList = approvalService.lambdaQuery().eq(Approval::getProjectId,projectManagement.getProId())
                    .eq(Approval::getApprovalType, Approval.APPROVAL_TYPE_EXPERT)
                    .eq(Approval::getExpertId,extractExpert.getExpertId())
                    .orderByDesc(Approval::getStartTime).list();
            Assert.isTrue(StringUtils.isNotEmpty(approvalList),"未找该专家的项目审核记录");
            Approval approval = approvalList.get(0);
            approval.setApprovalStatus(ProjectStatusEnum.ON_SITE_DEMONSTRATION_lAPPLY_CANCEL.get().getStatus());
            approval.setEndTime(LocalDateTime.now());
            approvalService.updateById(approval);
            //年度
        }else {
            List<Approval> approvalList = approvalService.lambdaQuery().eq(Approval::getPlanId,reviewTask.getPlanId())
                    .eq(Approval::getApprovalType, Approval.APPROVAL_TYPE_EXPERT)
                    .eq(Approval::getExpertId,extractExpert.getExpertId())
                    .orderByDesc(Approval::getCreateTime).list();
            Assert.isTrue(StringUtils.isNotEmpty(approvalList),"未找该专家的项目审核记录");
            Approval approval = approvalList.get(0);
            approval.setApprovalStatus(ProjectStatusEnum.ON_SITE_DEMONSTRATION_lAPPLY_CANCEL.get().getStatus());
            approval.setEndTime(LocalDateTime.now());
            approvalService.updateById(approval);
        }
        //增加该专家一条申请取消审核进程
        approvalService.save(new Approval(IdUtils.snowId(),projectManagement!=null?projectManagement.getProId():null,ProjectStatusEnum.APPROVAL_CANCEL_APPROVAL_AGAIN.get().getStage(),
                ProjectStatusEnum.APPROVAL_CANCEL_APPROVAL_AGAIN.get().getNode(),LocalDateTime.now(),null,null,ProjectStatusEnum.APPROVAL_CANCEL_APPROVAL_AGAIN.get().getStatus(),
                "/",null, null,null, LocalDateTime.now(),Approval.APPROVAL_TYPE_EXPERT,extractExpert.getExpertId(),reviewTask.getPlanId()!=null?reviewTask.getPlanId():null));
        reviewTaskService.updateById(reviewTask);
        return extractExpertService.updateById(extractExpert);
    }

    /**
     * 专家处理操作
     * @param reviewTaskId
     * @param receiveStatus
     * @param refuseReason
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean dealWith(Long reviewTaskId,String receiveStatus,String refuseReason){
        Long userId = SecurityUtils.getUserId();
        QueryWrapper<ExpertInformationSheet> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        queryWrapper.eq("del_flag",ExpertInformationSheet.DELETE_STATUS_NORMAL);
        List<ExpertInformationSheet> expertInformationSheetList = expertInformationSheetService.list(queryWrapper);
        Assert.isTrue(expertInformationSheetList.size()!=0,"该用户未绑定专家");
        Assert.isTrue(expertInformationSheetList.size()==1,"该用户绑定了多个专家，无法处理该评审任务");
        ExpertInformationSheet expertInfo = expertInformationSheetList.get(0);
        ExtractExpert extractExpert = reviewTaskMapper.extractExpertByReviewTaskId(reviewTaskId, expertInfo.getExpertId());
        Assert.isTrue(extractExpert.getStatus().equals(ExtractExpert.STATUS_NOT_ACCEPT),"状态为待接受才能进行处理操作!!!");
        extractExpert.setReceiveStatus(receiveStatus);
        extractExpert.setRefuseReason(refuseReason);
        extractExpert.setStatus(ExtractExpert.STATUS_REJECT);
        extractExpert.setDealTime(LocalDateTime.now());
        ReviewTask reviewTask = reviewTaskMapper.selectById(reviewTaskId);
        Assert.isTrue(StringUtils.isNotNull(reviewTask),"评审任务不存在");
        SysDept sysDept = deptService.selectDeptById(SecurityUtils.getDeptId());
        QueryWrapper<Object> queryWrapper1 = new QueryWrapper<>();
        ProjectManagementDetailsVo projectManagementDetailsVo = projectManagementService.selectProjectManagementListByReviewIds(reviewTaskId);
        //更新专家进程
        if(reviewTask.getReviewType().equals(ReviewTask.REVIEW_TYPE_PROGRAMME)){
            //更新专家审核进程为已接受任务
            approvalService.dealStayApproval(projectManagementDetailsVo!=null?projectManagementDetailsVo.getProId():null,ProjectStatusEnum.ACCEPT_NOT_TASK.get().getStatus(),
                    ProjectStatusEnum.ACCEPT_TASKED.get().getStatus(),null,extractExpert.getExpertId(),reviewTask.getPlanId()!=null?reviewTask.getPlanId():null,null);

        }else if(reviewTask.getReviewType().equals(ReviewTask.REVIEW_TYPE_ANNUAL)){
            List<Approval> approvalList = approvalService.lambdaQuery().eq(Approval::getPlanId, reviewTask.getPlanId())
                    .eq(Approval::getApprovalType, Approval.APPROVAL_TYPE_EXPERT)
                    .eq(Approval::getDelFlag, ExtractExpert.DELETE_STATUS_NORMAL)
                    .eq(Approval::getExpertId, extractExpert.getExpertId())
                    .orderByDesc(Approval::getCreateTime).list();
            Assert.isTrue(StringUtils.isNotEmpty(approvalList),"未找到该年度的审核进程");
            Approval approval = approvalList.get(0);
            approval.setEndTime(LocalDateTime.now());
            approval.setApprovalStatus(ProjectStatusEnum.ACCEPT_TASKED.get().getStatus());
            approvalService.updateById(approval);
        }
        //todo：评审专家接受评审任务
        if(ExtractExpert.RECEIVE_STATUS_ACCEPT.equals(receiveStatus)){
            extractExpert.setReceiveStatus(ExtractExpert.RECEIVE_STATUS_ACCEPT);
            extractExpert.setStatus(ExtractExpert.STATUS_APPLY_ACCEPT);
            extractExpert.setExtractNode(ProjectStatusEnum.ACCEPT_TASKED.get().getStatus());
            List<ExtractExpertDetailVo> extractExpertList = reviewTaskMapper.reviewTaskDetailById(reviewTaskId).getExtractExpertList();
            List<ExtractExpertDetailVo> collect = extractExpertList.stream().filter(s -> s.getReceiveStatus().equals(ExtractExpert.RECEIVE_STATUS_ACCEPT)).collect(Collectors.toList());
            List<Approval> approvalList = new ArrayList<>();
            List<ExtractExpert> extractExpertArrayList = new ArrayList<>();
            //所有专家都接受任务，更新评审任务的状态
            if(reviewTask.getExpertNum().equals(String.valueOf(collect.size()+1))) {
                reviewTask.setExpertStatus(ReviewTask.EXTRACT_STATUS_ACCEPTED);
                reviewTask.setNodeStatus(ProjectStatusEnum.ACCEPT_TASKED.get().getStatus());
                //项目评审:评审任务节点为在线预审 状态为待审批; 并更新项目信息和进程、新增在线预审进程
                if (reviewTask.getReviewType().equals(ReviewTask.REVIEW_TYPE_PROGRAMME)) {
                    extractExpert.setStatus(ExtractExpert.STATUS_NOT_APPROVAL);
                    extractExpert.setExtractNode(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStatus());
                    Assert.isTrue(StringUtils.isNotNull(projectManagementDetailsVo),"未找到相应的项目信息");
                    ProjectManagement projectManagement = projectManagementService.getById(projectManagementDetailsVo.getProId());
                    Assert.isTrue(StringUtils.isNotNull(projectManagement),"未找到该项目信息");
                    List<ProjectManagement> projectManagementList = projectManagementService.lambdaQuery().eq(ProjectManagement::getReviewTaskId, reviewTask.getReviewTaskId())
                            .eq(ProjectManagement::getIsDelete, ExtractExpert.DELETE_STATUS_NORMAL).list();
                    Assert.isTrue(!Collections.isEmpty(projectManagementList), "项目信息未关联该评审任务");
                    //更新项目信息和进程、新增在线预审进程
                    LocalDateTime localDateTime=LocalDateTime.now();
                    approvalService.dealStayApproval(projectManagementList.get(0).getProId(), ProjectStatusEnum.ACCEPT_NOT_TASK.get().getStatus(),
                            ProjectStatusEnum.ACCEPT_TASKED.get().getStatus(), null,null,null,null);
                    approvalService.save(new Approval(IdUtils.snowId(), projectManagement.getProId(), ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStage(),
                            ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getNode(), LocalDateTime.now(), null, null, ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStatus(),
                            "/", null, null, null, localDateTime, Approval.APPROVAL_TYPE_PROJECT_MANAGE));
                    //新增多个专家在线预审进程
                   extractExpertList.stream().forEach(s->{
                        Approval approval = new Approval(IdUtils.snowId(),projectManagementDetailsVo.getProId(),ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStage(),
                                ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getNode(),LocalDateTime.now(),null,null,ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStatus(),
                                "/",null, null,null, localDateTime,Approval.APPROVAL_TYPE_EXPERT,s.getExpertId(),null);
                        approvalList.add(approval);
                   });
                    //每个专家更新抽取表状态为在线预审待审
                    List<ExtractExpert> extractExperts = reviewTaskService.getExtractExpertList(reviewTaskId);
                    Assert.isTrue(StringUtils.isNotEmpty(extractExperts),"该评审任务未找到专家抽取表信息");
                    extractExperts.stream().forEach(s->{
                        ExtractExpert expert = new ExtractExpert();
                        BeanUtils.copyProperties(s,expert);
                        expert.setStatus(ExtractExpert.STATUS_NOT_APPROVAL);
                        expert.setExtractNode(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStatus());
                        extractExpertArrayList.add(expert);
                    });
                    extractExpertService.saveOrUpdateBatch(extractExpertArrayList);
                    approvalService.batchApproval(approvalList);
                    reviewTask.setNodeStatus(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStatus());
                    reviewTask.setNode(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getNode());
                    reviewTaskService.updateById(reviewTask);
                    projectManagement.setIsState(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStatus());
                    projectManagement.setNode(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getNode());
                    projectManagement.setStag(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStage());
                    projectManagementService.updateById(projectManagement);
                    //同步项目数据到项目信息表中
                    approvalService.synchronizationProjectInfo(projectManagement);
                    //年度评审：评审任务节点为现场论证 状态为已接受;
                }else if(reviewTask.getReviewType().equals(ReviewTask.REVIEW_TYPE_ANNUAL)){
                    reviewTask.setNodeStatus(ProjectStatusEnum.THE_ONSITE_DEMONSTRATION_HAS_BEEN_PASSED.get().getStatus());
                    reviewTask.setNode(ProjectStatusEnum.THE_ONSITE_DEMONSTRATION_HAS_BEEN_PASSED.get().getNode());
                    extractExpert.setStatus(ExtractExpert.STATUS_NOT_START);
                    extractExpert.setExtractNode(ProjectStatusEnum.THE_ONSITE_DEMONSTRATION_HAS_BEEN_PASSED.get().getStatus());
                    //新增多个专家现场论证进程
                    List<ExtractExpert> list = new ArrayList<>();
                    extractExpertList.stream().forEach(s->{
                        Approval approval = new Approval(IdUtils.snowId(),projectManagementDetailsVo!=null?projectManagementDetailsVo.getProId():null,ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStage(),
                                ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getNode(),LocalDateTime.now(),LocalDateTime.now(),SecurityUtils.getNickName(),ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus(),
                                "/",null, null,null, LocalDateTime.now(),Approval.APPROVAL_TYPE_EXPERT,s.getExpertId(),reviewTask.getPlanId());
                        approvalList.add(approval);
                        //同步抽取表状态为现场论证待开始
                        ExtractExpert expert = new ExtractExpert();
                        BeanUtils.copyProperties(s,expert);
                        expert.setStatus(ExtractExpert.STATUS_NOT_START);
                        expert.setExtractNode(ProjectStatusEnum.THE_ONSITE_DEMONSTRATION_HAS_BEEN_PASSED.get().getStatus());
                        list.add(expert);
                    });
                    extractExpertService.saveOrUpdateBatch(list);
                    approvalService.batchApproval(approvalList);


                }
            }
            //新增专家确认进程
            ExpertInformationSheetDetailVo infoByUserId = expertInformationSheetService.getInfoByUserId();
            expertCourseService.save(new ExpertCourse(IdUtils.snowId(),reviewTaskId,infoByUserId.getExpertName()+
                    dictDataService.selectDictLabel("receive_status",receiveStatus)+"评审任务",LocalDateTime.now()));
            //生成对应系统消息--大数据局
            if(StringUtils.isNull(reviewTask.getOrmId())){
                if(ReviewTask.REVIEW_TYPE_ANNUAL.equals(reviewTask.getReviewType())){
                    //年度清单评审消息
                    AnnualProjectPlan annualProjectPlan = annualProjectPlanService.getById(reviewTask.getPlanId());
                    Assert.isTrue(StringUtils.isNotNull(annualProjectPlan),"未找到年度计划信息信息");
                    String content=annualProjectPlan.getName()+ CreateMsgUtil.TASKED+expertInfo.getExpertName()+CreateMsgUtil.ACCEPT_TASKED;
                    //大数据局收到消息
                    List<Long> bigDataId = userRoleMapper.getUserIdByRoleId(Constants.ROLE_TYPE_BIGDATA);
                    List<Long> bigDataNormalId = userRoleMapper.getUserIdByRoleId(Constants.ROLE_TYPE_BIGDATA_NORMAL);
                    bigDataId.addAll(bigDataNormalId);
                    bigDataId.forEach(s->{
                        CreateMsgUtil.createMsg(content,s,null,CreateMsgUtil.TASKED_TITLE, SysMsg.RESOURCE_TYPE_DATA,null,null);
                    });


                }else {
                    //方案评审消息
                    String content=projectManagementDetailsVo.getName()+ CreateMsgUtil.SCHEME_TASKED+expertInfo.getExpertName()+CreateMsgUtil.ACCEPT_TASKED;
                    //大数据局收到消息
                    List<Long> bigDataId = userRoleMapper.getUserIdByRoleId(Constants.ROLE_TYPE_BIGDATA);
                    List<Long> bigDataNormalId = userRoleMapper.getUserIdByRoleId(Constants.ROLE_TYPE_BIGDATA_NORMAL);
                    bigDataId.addAll(bigDataNormalId);
                    bigDataId.forEach(s->{
                        CreateMsgUtil.createMsg(content,s,null,CreateMsgUtil.TASKED_TITLE, SysMsg.RESOURCE_TYPE_DATA,null,null);
                    });
                }
                //三方机构
            }else {
                String content=projectManagementDetailsVo.getName()+ CreateMsgUtil.TASKED+expertInfo.getExpertName()+CreateMsgUtil.ACCEPT_TASKED;
                OrganizationManagement organizationManagement = organizationManagementService.selectOrganizationManagementByOrmId(reviewTask.getOrmId());
                SysUser sysUser = new SysUser();
                sysUser.setDeptId(organizationManagement.getDeptId());
                List<SysUser> sysUsers = userService.selectUserList(sysUser);
                sysUsers.forEach(s->{
                    CreateMsgUtil.createMsg(content,s.getUserId(),null,CreateMsgUtil.TASKED_TITLE, SysMsg.RESOURCE_TYPE_DATA,String.valueOf(reviewTask.getOrmId()),null);
                });

            }
        }else {
            //新增专家解决进程
            ExpertInformationSheetDetailVo infoByUserId = expertInformationSheetService.getInfoByUserId();
            expertCourseService.save(new ExpertCourse(IdUtils.snowId(),reviewTaskId,infoByUserId.getExpertName()+
                    dictDataService.selectDictLabel("receive_status",receiveStatus)+"评审任务",LocalDateTime.now()));
        }
        extractExpertService.updateById(extractExpert);
        return reviewTaskService.updateById(reviewTask);
    }

    /**
     * 查看专家是否是接受任务详情
     * @param reviewTaskId
     * @return
     */
    @Override
    public ExpertIsReceiveReviewTaskDetailVo receiveTaskDetail(Long reviewTaskId,Long expertId){
        //判断当前登录的人是否是专家
        QueryWrapper<ExpertInformationSheet> expertInfoSheetQueryWrapper = new QueryWrapper<>();
        expertInfoSheetQueryWrapper.eq("expert_id",expertId);
        expertInfoSheetQueryWrapper.eq("del_flag",ExpertInformationSheet.DELETE_STATUS_NORMAL);
        ExpertInformationSheet expertInfo = expertInformationSheetService.getOne(expertInfoSheetQueryWrapper);
        Assert.isTrue(StringUtils.isNotNull(expertInfo),"专家未绑定账号，请绑定账号!!!");
        SysUser user = userService.selectUserById(expertInfo.getUserId());
        List<SysRole> roles= roleService.selectRolesByUserId(user.getUserId());
        Assert.isTrue(StringUtils.isNotNull(roles.get(0)) && !roles.get(0).getRoleId().equals(104L),"用户与角色未绑定!!!");
        ExpertIsReceiveReviewTaskDetailVo detailVo =  reviewTaskMapper.selectAcceptDetail(reviewTaskId,expertId);
        Assert.isTrue(StringUtils.isNotNull(detailVo),"详情不存在!!!");
        return detailVo;
    }

    @Override
    public List<SysDept> extractUnit() {
        List<SysDept> list = new ArrayList<>();
        List<SysDept> sysDepts = deptService.selectDeptList(new SysDept(102L));
        sysDepts.stream().forEach(s->{
            list.add(s);
        });
        list.add(deptService.selectDeptById(104L));
        return list;
    }

    @Override
    public List<ExtractExpert> getExtractExpertList(Long reviewTaskId) {
        return reviewTaskMapper.getExtractExpertList(reviewTaskId);
    }

    @Override
    public int edit(ReviewTaskEditDto dto) {
        ProjectManagement projectManagement = projectManagementService.getById(dto.getProId());
        Assert.isTrue(StringUtils.isNotNull(projectManagement),"未找到该项目信息");
        ReviewTask reviewTask = reviewTaskMapper.selectById(projectManagement.getReviewTaskId());
        Assert.isTrue(StringUtils.isNotNull(reviewTask),"未找到该评审任务信息");
        reviewTask.setReviewAddress(dto.getReviewAddress());
        reviewTask.setReviewTimeStart(dto.getReviewTimeStart());
        reviewTask.setReviewTimeEnd(dto.getReviewTimeEnd());
        //审核进程、项目信息、评审任务更新为在线预审待审核
        Approval approval = approvalService.getApproval(projectManagement.getProId(), ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_ARRANGE.get().getStatus(), null, null);
        approval.setApprovalNode(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getNode());
        approval.setApprovalStage(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStage());
        approval.setApprovalStatus(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStatus());
        approval.setEndTime(null);
        projectManagement.setIsState(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStatus());
        projectManagement.setNode(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getNode());
        projectManagement.setStag(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStage());
        //同步评审任务节点
        reviewTask.setNode(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getNode());
        reviewTask.setNodeStatus(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStatus());
//       抽取表下所有抽取出专家，新增每个专家在线预审进程
        List<Approval> approvalList = new ArrayList<>();
        List<ExtractExpert> arrayList = new ArrayList<>();
        List<ExtractExpert> extractExperts = reviewTaskService.getExtractExpertList(reviewTask.getReviewTaskId());
        Assert.isTrue(StringUtils.isNotEmpty(extractExperts),"该评审任务未找到专家抽取表信息");
        extractExperts.stream().forEach(s->{
            ExtractExpert expert = new ExtractExpert();
            BeanUtils.copyProperties(s,expert);
            expert.setExtractNode(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStatus());
            expert.setStatus(ExtractExpert.STATUS_NOT_APPROVAL);
            arrayList.add(expert);
            Approval approvalSummary = new Approval(IdUtils.snowId(),projectManagement.getProId(),ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL_AGAIN.get().getStage(),
                    ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL_AGAIN.get().getNode(),LocalDateTime.now(),null,null,ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL_AGAIN.get().getStatus(),
                    "/",null, null,null, approval.getCreateTime(),Approval.APPROVAL_TYPE_EXPERT,s.getExpertId(),null);
            approvalList.add(approvalSummary);
            //todo 对接短信接口
        });
        //所有专家现场论证审核进程更新结束时间 状态为已结束
        //获取最新一条现场论证创建时间
        List<Approval> latestApprovalList = approvalService.lambdaQuery().eq(Approval::getProjectId, projectManagement.getProId())
                .eq(Approval::getApprovalType, Approval.APPROVAL_TYPE_PROJECT_MANAGE)
                .eq(Approval::getApprovalNode, ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getNode())
                .list();
        if(StringUtils.isNotEmpty(latestApprovalList)){
            List<Approval> collect = latestApprovalList.stream().sorted(Comparator.comparing(Approval::getCreateTime).reversed()).collect(Collectors.toList());
            LocalDateTime createTime = collect.get(0).getCreateTime();
            List<Approval> approvals = approvalService.lambdaQuery().eq(Approval::getProjectId, projectManagement.getProId())
                    .eq(Approval::getApprovalType, Approval.APPROVAL_TYPE_EXPERT)
                    .eq(Approval::getApprovalStatus, ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus())
                    .eq(Approval::getCreateTime,createTime).list();
            if(StringUtils.isNotEmpty(approvals)){
                approvals.stream().forEach(s->{
                    s.setEndTime(LocalDateTime.now());
                    s.setApprovalStatus(ProjectStatusEnum.THE_ONSITE_DEMONSTRATION_HAS_BEEN_PASSED.get().getStatus());
                });
                approvalService.saveOrUpdateBatch(approvals);
            }
        }

        approvalService.batchApproval(approvalList);
        extractExpertService.saveOrUpdateBatch(arrayList);
        approvalService.updateById(approval);
        projectManagementService.updateById(projectManagement);
        return reviewTaskMapper.updateById(reviewTask);
    }

    @Override
    public ReviewTaskDetailVo detailTask(Long reviewTaskId) {
        ReviewTaskDetailVo reviewTaskDetailVo = reviewTaskMapper.reviewTaskDetail(reviewTaskId);
        //增加判断类型：该抽取规则是否可以更换专家
        List<ExtractExpertDetailVo> extractExpertList = reviewTaskDetailVo.getExtractExpertList();
        extractExpertList.stream().forEach(s->{
            ExchangeExpertDto exchangeExpertDto = new ExchangeExpertDto();
            exchangeExpertDto.setExtractExpertId(s.getExtractExpertId());
            exchangeExpertDto.setReviewTaskId(reviewTaskId);
            ExpertInformationSheetDetailVo expertInformationSheetDetailVo = extractRuleService.selectExchangeExpertInfo(exchangeExpertDto);
            s.setType(StringUtils.isNull(expertInformationSheetDetailVo)?"1":"0");
            //返回对应职称
            List<TechnicalTitle> technicalTitleList = technicalTitleService.lambdaQuery().eq(TechnicalTitle::getExpertId, s.getExpertId()).list();
            if(StringUtils.isNotEmpty(technicalTitleList)){
                List<String> collect = technicalTitleList.stream().map(TechnicalTitle::getJobTitle).collect(Collectors.toList());
                List<String> technicalList = new ArrayList<>();
                collect.stream().forEach(a->{
                    technicalList.add(dictDataService.selectDictLabel("technical_type", a));
                });
                s.setTechnicalName(StringUtils.join(technicalList,","));
            }
        });
        return reviewTaskDetailVo;
    }

    @Override
    public List<ExpertMessageVo> expertMessage(Long expertId) {
        return reviewTaskMapper.expertMessage(expertId);
    }

    @Override
    public ReviewTaskVo findReviewTaskVo(Long approvalId) {
        Approval approval = approvalService.getById(approvalId);
        String approvalOperation = approval.getApprovalOperation();
        ReviewTaskVo reviewTaskVo = JSON.parseObject(approvalOperation,ReviewTaskVo.class);
        return reviewTaskVo;
    }

    @Override
    public ExtractExpert extractExpertByReviewTaskId(Long reviewTaskId, Long expertId) {
        return reviewTaskMapper.extractExpertByReviewTaskId(reviewTaskId,expertId);
    }

    private List<ApprovalVo> getApprovalVoList(List<Approval> thirdApprovalList){
        ArrayList<ApprovalVo> approvalVoList = new ArrayList<>();
        List<Approval> collect2 = thirdApprovalList.stream().sorted(Comparator.comparing(Approval::getStartTime)).collect(Collectors.toList());
        collect2.stream().forEach(s-> {
            List<YzqFile> fileList = new ArrayList<>();
            ApprovalVo approvalVo = new ApprovalVo();
            BeanUtils.copyProperties(s, approvalVo);
            approvalVo.setApprovalStatusName(ProjectStatusEnum.getEnum(approvalVo.getApprovalStatus()).getStatusDes());
            if (StringUtils.isNotNull(approvalVo.getApprovalDatabase())) {
                if (approvalVo.getApprovalDatabase().contains(",")) {
                    List<String> fileNameList = new ArrayList<String>();
                    StringTokenizer st = new StringTokenizer(approvalVo.getApprovalDatabase(), ",");
                    while (st.hasMoreTokens()) {
                        String s1 = st.nextToken();
                        YzqFile yzqFile = fileService.getById(s1);
                        if (StringUtils.isNotNull(yzqFile)) {
                            fileList.add(yzqFile);
                            String fileName = yzqFile.getFileName();
                            if (StringUtils.isNotEmpty(fileName)) {
                                fileNameList.add(fileName);
                            }

                        }
                    }
                    approvalVo.setApprovalDatabaseName(String.join(";", fileNameList));
                } else {
                    YzqFile file = fileService.getById(approvalVo.getApprovalDatabase());
                    if (file != null) {
                        fileList.add(file);
                        approvalVo.setApprovalDatabaseName(file.getFileName());
                    }

                }
                approvalVo.setRelationFile(fileList);
            }
            approvalVoList.add(approvalVo);
        });
        return approvalVoList;
    }
    /**
     * 专家处理操作
     * @param reviewTaskId
     * @param receiveStatus
     * @param refuseReason
     * @param userId
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean dealWithH5(Long reviewTaskId,String receiveStatus,String refuseReason,Long userId){
        QueryWrapper<ExpertInformationSheet> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        queryWrapper.eq("del_flag",ExpertInformationSheet.DELETE_STATUS_NORMAL);
        List<ExpertInformationSheet> expertInformationSheetList = expertInformationSheetService.list(queryWrapper);
        Assert.isTrue(expertInformationSheetList.size()!=0,"该用户未绑定专家");
        Assert.isTrue(expertInformationSheetList.size()==1,"该用户绑定了多个专家，无法处理该评审任务");
        ExpertInformationSheet expertInfo = expertInformationSheetList.get(0);
        ExtractExpert extractExpert = reviewTaskMapper.extractExpertByReviewTaskId(reviewTaskId, expertInfo.getExpertId());
        Assert.isTrue(extractExpert.getStatus().equals(ExtractExpert.STATUS_NOT_ACCEPT),"状态为待接受才能进行处理操作!!!");
        extractExpert.setReceiveStatus(receiveStatus);
        extractExpert.setRefuseReason(refuseReason);
        extractExpert.setStatus(ExtractExpert.STATUS_REJECT);
        extractExpert.setDealTime(LocalDateTime.now());
        ReviewTask reviewTask = reviewTaskMapper.selectById(reviewTaskId);
        Assert.isTrue(StringUtils.isNotNull(reviewTask),"评审任务不存在");
        QueryWrapper<Object> queryWrapper1 = new QueryWrapper<>();
        ProjectManagementDetailsVo projectManagementDetailsVo = projectManagementService.selectProjectManagementListByReviewIds(reviewTaskId);
        //更新专家进程
        if(reviewTask.getReviewType().equals(ReviewTask.REVIEW_TYPE_PROGRAMME)){
            //更新专家审核进程为已接受任务
            approvalService.dealStayApproval(projectManagementDetailsVo!=null?projectManagementDetailsVo.getProId():null,ProjectStatusEnum.ACCEPT_NOT_TASK.get().getStatus(),
                    ProjectStatusEnum.ACCEPT_TASKED.get().getStatus(),null,extractExpert.getExpertId(),reviewTask.getPlanId()!=null?reviewTask.getPlanId():null,null);

        }else if(reviewTask.getReviewType().equals(ReviewTask.REVIEW_TYPE_ANNUAL)){
            List<Approval> approvalList = approvalService.lambdaQuery().eq(Approval::getPlanId, reviewTask.getPlanId())
                    .eq(Approval::getApprovalType, Approval.APPROVAL_TYPE_EXPERT)
                    .eq(Approval::getDelFlag, ExtractExpert.DELETE_STATUS_NORMAL)
                    .eq(Approval::getExpertId, extractExpert.getExpertId())
                    .orderByDesc(Approval::getCreateTime).list();
            Assert.isTrue(StringUtils.isNotEmpty(approvalList),"未找到该年度的审核进程");
            Approval approval = approvalList.get(0);
            approval.setEndTime(LocalDateTime.now());
            approval.setApprovalStatus(ProjectStatusEnum.ACCEPT_TASKED.get().getStatus());
            approvalService.updateById(approval);
        }
        //todo：评审专家接受评审任务
        if(ExtractExpert.RECEIVE_STATUS_ACCEPT.equals(receiveStatus)){
            extractExpert.setReceiveStatus(ExtractExpert.RECEIVE_STATUS_ACCEPT);
            extractExpert.setStatus(ExtractExpert.STATUS_APPLY_ACCEPT);
            extractExpert.setExtractNode(ProjectStatusEnum.ACCEPT_TASKED.get().getStatus());
            List<ExtractExpertDetailVo> extractExpertList = reviewTaskMapper.reviewTaskDetailById(reviewTaskId).getExtractExpertList();
            List<ExtractExpertDetailVo> collect = extractExpertList.stream().filter(s -> s.getReceiveStatus().equals(ExtractExpert.RECEIVE_STATUS_ACCEPT)).collect(Collectors.toList());
            List<Approval> approvalList = new ArrayList<>();
            List<ExtractExpert> extractExpertArrayList = new ArrayList<>();
            //所有专家都接受任务，更新评审任务的状态
            if(reviewTask.getExpertNum().equals(String.valueOf(collect.size()+1))) {
                reviewTask.setExpertStatus(ReviewTask.EXTRACT_STATUS_ACCEPTED);
                reviewTask.setNodeStatus(ProjectStatusEnum.ACCEPT_TASKED.get().getStatus());
                //项目评审:评审任务节点为在线预审 状态为待审批; 并更新项目信息和进程、新增在线预审进程
                if (reviewTask.getReviewType().equals(ReviewTask.REVIEW_TYPE_PROGRAMME)) {
                    extractExpert.setStatus(ExtractExpert.STATUS_NOT_APPROVAL);
                    extractExpert.setExtractNode(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStatus());
                    Assert.isTrue(StringUtils.isNotNull(projectManagementDetailsVo),"未找到相应的项目信息");
                    ProjectManagement projectManagement = projectManagementService.getById(projectManagementDetailsVo.getProId());
                    Assert.isTrue(StringUtils.isNotNull(projectManagement),"未找到该项目信息");
                    List<ProjectManagement> projectManagementList = projectManagementService.lambdaQuery().eq(ProjectManagement::getReviewTaskId, reviewTask.getReviewTaskId())
                            .eq(ProjectManagement::getIsDelete, ExtractExpert.DELETE_STATUS_NORMAL).list();
                    Assert.isTrue(!Collections.isEmpty(projectManagementList), "项目信息未关联该评审任务");
                    //更新项目信息和进程、新增在线预审进程
                    LocalDateTime localDateTime=LocalDateTime.now();
                    approvalService.dealStayApproval(projectManagementList.get(0).getProId(), ProjectStatusEnum.ACCEPT_NOT_TASK.get().getStatus(),
                            ProjectStatusEnum.ACCEPT_TASKED.get().getStatus(), null,null,null,null);
                    approvalService.save(new Approval(IdUtils.snowId(), projectManagement.getProId(), ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStage(),
                            ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getNode(), LocalDateTime.now(), null, null, ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStatus(),
                            "/", null, null, null, localDateTime, Approval.APPROVAL_TYPE_PROJECT_MANAGE));
                    //新增多个专家在线预审进程
                    extractExpertList.stream().forEach(s->{
                        Approval approval = new Approval(IdUtils.snowId(),projectManagementDetailsVo.getProId(),ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStage(),
                                ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getNode(),LocalDateTime.now(),null,null,ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStatus(),
                                "/",null, null,null, localDateTime,Approval.APPROVAL_TYPE_EXPERT,s.getExpertId(),null);
                        approvalList.add(approval);
                    });
                    //每个专家更新抽取表状态为在线预审待审
                    List<ExtractExpert> extractExperts = reviewTaskService.getExtractExpertList(reviewTaskId);
                    Assert.isTrue(StringUtils.isNotEmpty(extractExperts),"该评审任务未找到专家抽取表信息");
                    extractExperts.stream().forEach(s->{
                        ExtractExpert expert = new ExtractExpert();
                        BeanUtils.copyProperties(s,expert);
                        expert.setStatus(ExtractExpert.STATUS_NOT_APPROVAL);
                        expert.setExtractNode(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStatus());
                        extractExpertArrayList.add(expert);
                    });
                    extractExpertService.saveOrUpdateBatch(extractExpertArrayList);
                    approvalService.batchApproval(approvalList);
                    reviewTask.setNodeStatus(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStatus());
                    reviewTask.setNode(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getNode());
                    reviewTaskService.updateById(reviewTask);
                    projectManagement.setIsState(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStatus());
                    projectManagement.setNode(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getNode());
                    projectManagement.setStag(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStage());
                    projectManagementService.updateById(projectManagement);
                    //年度评审：评审任务节点为现场论证 状态为已接受;
                }else if(reviewTask.getReviewType().equals(ReviewTask.REVIEW_TYPE_ANNUAL)){
                    reviewTask.setNodeStatus(ProjectStatusEnum.THE_ONSITE_DEMONSTRATION_HAS_BEEN_PASSED.get().getStatus());
                    reviewTask.setNode(ProjectStatusEnum.THE_ONSITE_DEMONSTRATION_HAS_BEEN_PASSED.get().getNode());
                    extractExpert.setStatus(ExtractExpert.STATUS_NOT_START);
                    extractExpert.setExtractNode(ProjectStatusEnum.THE_ONSITE_DEMONSTRATION_HAS_BEEN_PASSED.get().getStatus());
                    //新增多个专家现场论证进程
                    List<ExtractExpert> list = new ArrayList<>();
                    extractExpertList.stream().forEach(s->{
                        Approval approval = new Approval(IdUtils.snowId(),projectManagementDetailsVo!=null?projectManagementDetailsVo.getProId():null,ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStage(),
                                ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getNode(),LocalDateTime.now(),LocalDateTime.now(),null,ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus(),
                                "/",null, null,null, LocalDateTime.now(),Approval.APPROVAL_TYPE_EXPERT,s.getExpertId(),reviewTask.getPlanId());
                        approvalList.add(approval);
                        //同步抽取表状态为现场论证待开始
                        ExtractExpert expert = new ExtractExpert();
                        BeanUtils.copyProperties(s,expert);
                        expert.setStatus(ExtractExpert.STATUS_NOT_START);
                        expert.setExtractNode(ProjectStatusEnum.THE_ONSITE_DEMONSTRATION_HAS_BEEN_PASSED.get().getStatus());
                        list.add(expert);
                    });
                    extractExpertService.saveOrUpdateBatch(list);
                    approvalService.batchApproval(approvalList);


                }
            }
            //新增专家确认进程
            ExpertInformationSheetDetailVo infoByUserId = expertInformationSheetMapper.getInfoByUserId(userId);
            expertCourseService.save(new ExpertCourse(IdUtils.snowId(),reviewTaskId,infoByUserId.getExpertName()+
                    dictDataService.selectDictLabel("receive_status",receiveStatus)+"评审任务",LocalDateTime.now()));
            //生成对应系统消息--大数据局
            if(StringUtils.isNull(reviewTask.getOrmId())){
                if(ReviewTask.REVIEW_TYPE_ANNUAL.equals(reviewTask.getReviewType())){
                    //年度清单评审消息
                    AnnualProjectPlan annualProjectPlan = annualProjectPlanService.getById(reviewTask.getPlanId());
                    Assert.isTrue(StringUtils.isNotNull(annualProjectPlan),"未找到年度计划信息信息");
                    String content=annualProjectPlan.getName()+ CreateMsgUtil.TASKED+expertInfo.getExpertName()+CreateMsgUtil.ACCEPT_TASKED;
                    //大数据局收到消息
                    List<Long> bigDataId = userRoleMapper.getUserIdByRoleId(Constants.ROLE_TYPE_BIGDATA);
                    List<Long> bigDataNormalId = userRoleMapper.getUserIdByRoleId(Constants.ROLE_TYPE_BIGDATA_NORMAL);
                    bigDataId.addAll(bigDataNormalId);
                    bigDataId.forEach(s->{
                        CreateMsgUtil.createMsgH5(content,s,null,CreateMsgUtil.TASKED_TITLE, SysMsg.RESOURCE_TYPE_DATA,null,null);
                    });


                }else {
                    //方案评审消息
                    String content=projectManagementDetailsVo.getName()+ CreateMsgUtil.SCHEME_TASKED+expertInfo.getExpertName()+CreateMsgUtil.ACCEPT_TASKED;
                    //大数据局收到消息
                    List<Long> bigDataId = userRoleMapper.getUserIdByRoleId(Constants.ROLE_TYPE_BIGDATA);
                    List<Long> bigDataNormalId = userRoleMapper.getUserIdByRoleId(Constants.ROLE_TYPE_BIGDATA_NORMAL);
                    bigDataId.addAll(bigDataNormalId);
                    bigDataId.forEach(s->{
                        CreateMsgUtil.createMsgH5(content,s,null,CreateMsgUtil.TASKED_TITLE, SysMsg.RESOURCE_TYPE_DATA,null,null);
                    });
                }
                //三方机构
            }else {
                String content=projectManagementDetailsVo.getName()+ CreateMsgUtil.TASKED+expertInfo.getExpertName()+CreateMsgUtil.ACCEPT_TASKED;
                OrganizationManagement organizationManagement = organizationManagementService.selectOrganizationManagementByOrmId(reviewTask.getOrmId());
                SysUser sysUser = new SysUser();
                sysUser.setDeptId(organizationManagement.getDeptId());
                List<SysUser> sysUsers = userMapper.selectUserList(sysUser);
                sysUsers.forEach(s->{
                    CreateMsgUtil.createMsgH5(content,s.getUserId(),null,CreateMsgUtil.TASKED_TITLE, SysMsg.RESOURCE_TYPE_DATA,String.valueOf(reviewTask.getOrmId()),null);
                });

            }
        }else {
            //新增专家解决进程
            ExpertInformationSheetDetailVo infoByUserId = expertInformationSheetMapper.getInfoByUserId(userId);
            expertCourseService.save(new ExpertCourse(IdUtils.snowId(),reviewTaskId,infoByUserId.getExpertName()+
                    dictDataService.selectDictLabel("receive_status",receiveStatus)+"评审任务",LocalDateTime.now()));
        }
        extractExpertService.updateById(extractExpert);
        return reviewTaskService.updateById(reviewTask);
    }
}
